package com.banban.user.service.impl;

import com.banban.user.domain.PromptTemplate;
import com.banban.user.service.AliyunOssService;
import com.banban.user.service.PromptTemplateService;
import com.banban.user.service.TestService;
import com.banban.user.util.DeepSeekSendMessage;
import com.banban.user.util.UniqueIDUtil;
import com.banban.user.vo.FileUploadVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Objects;

@Service
public class TestServiceImpl implements TestService {

    @Value("${oss.Bucket}")
    private String Bucket;

    @Autowired
    private DeepSeekSendMessage deepSeekSendMessage;

    @Resource
    private PromptTemplateService promptTemplateService;

    @Resource
    private AliyunOssService aliyunOssService;

    public static final String RESOURCE_OSS_KEY="resource/staticResource/";

    @Override
    public String upload(MultipartFile multipartFile) throws IOException {
        if (Objects.nonNull(multipartFile) && !multipartFile.isEmpty()) {
            String fileName = multipartFile.getOriginalFilename();
            String osskey = RESOURCE_OSS_KEY + UniqueIDUtil.generateId() + fileName;
            String url = aliyunOssService.uploadFile(Bucket, osskey, multipartFile.getInputStream());
            FileUploadVO fileUploadVO = FileUploadVO.builder().fileName(fileName)
                    .uri(url).build();
            return fileUploadVO.getUri();
        }
        return "";
    }

    @Override
    public String chatWithTemplate(String prompt, String templateId) throws IOException {
        PromptTemplate promptTemplate = promptTemplateService.getById(templateId);
        String prompt1 = promptTemplate.getPrompt();
        return deepSeekSendMessage.getResponse(prompt, prompt1);
    }

    String a  = "[{\"requestId\":\"123\",\"createBy\":\"张三\",\"userMessage\":\"我天天在抖音看新闻，来了解国家大事\",\"assistantMessage\":\"哇，你好棒啊\"},{\"requestId\":\"45646\",\"createBy\":\"张三\",\"userMessage\":\"我最烦有人天天催我干什么事，一提就来气\",\"assistantMessage\":\"好吧\"},{\"requestId\":\"897689689\",\"createBy\":\"张三\",\"userMessage\":\"我之前买的那个4060显卡太难用了，黑神话悟空玩着特别卡\",\"assistantMessage\":\"你可以尝试换一个高端点的显卡试试\"}]";
}
